package com.qf.mapper;

import com.qf.entity.SysPermission;
import com.qf.entity.SysRoleEntity;
import com.qf.entity.SysUser;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface UserMapper {

    @Select("select * from sys_user where user_name=#{username}")
    SysUser findByNP(String username);

    @Select("select r.* from sys_user u left join sys_user_role sr on sr.user_id=u.user_id " +
            "left join sys_role r on r.role_code=sr.role_id where u.user_id = #{userId}")
    List<SysRoleEntity> findRoles(String userId);

    @Select("SELECT sp.* FROM sys_user u \n" +
            "\t\tLEFT JOIN sys_user_role sr ON sr.user_id=u.user_id\n" +
            "LEFT JOIN sys_role_permission srp ON srp.role_id=sr.role_id\n" +
            "LEFT JOIN sys_permission sp ON sp.perm_code = srp.perm_id\n" +
            "WHERE u.user_id = #{userId}")
    List<SysPermission> findPermission(String userId);
}
